 ///
 /// @file    observer.h
 /// @author  lemon(haohb13@gmail.com)
 /// @date    2016-03-17 15:44:55
 ///
 
#ifndef _MY_OBSERVER_H__
#define _MY_OBSERVER_H__

#include <list>
using std::list;

typedef int State;

class Observer;

class Subject
{
public:
	Subject(): _myState(-1){}
	void attach(Observer *);
	void detach(Observer *);
	void notify();

	virtual State getState();
	virtual void setState(State nState);
	virtual ~Subject();
protected:
	State _myState;
	list<Observer *> _observerList;
};

class Observer
{
public:
	Observer() : _observerState(-1){}
	virtual void update(Subject * subject)=0;
	virtual ~Observer(){}
protected:
	State _observerState;
};


class ConcreateSubject : public Subject
{
public:
	ConcreateSubject(){}
	virtual State getState();
	virtual void setState(State nState);
};


class ConcreateObserver : public Observer
{
public:
	ConcreateObserver(){}
	virtual void update(Subject * subject);
};
#endif
